package com.fzu.normalservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fzu.commonutil.entity.Demand;
import com.fzu.commonutil.entity.ServiceType;
import com.fzu.commonutil.entity.User;
import com.fzu.commonutil.mapper.ServiceTypeMapper;
import com.fzu.commonutil.util.PageVO;
import com.fzu.normalservice.service.ServiceTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyq
 * @since 2023-04-03
 */
@Service
public class ServiceTypeServiceImpl extends ServiceImpl<ServiceTypeMapper, ServiceType> implements ServiceTypeService {

    @Override
    public List<ServiceType> list(ServiceType serviceType) {
        LambdaQueryWrapper<ServiceType> wrapper = new LambdaQueryWrapper<>();
        String name = serviceType.getName();
        if (StringUtils.isNotBlank(name)) {
            wrapper.eq(ServiceType::getName, serviceType.getName());
        }
        Integer state = serviceType.getState();
        if (state != null) {
            wrapper.eq(ServiceType::getState, state);
        }
        wrapper.orderByAsc(ServiceType::getSeq);
        return super.list(wrapper);
    }

    @Override
    public PageVO page(ServiceType serviceType, Integer pageNum, Integer pageSize) {
        // 构造分页参数
        Page<ServiceType> pageRequest = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<ServiceType> wrapper = new LambdaQueryWrapper<>();

        String name = serviceType.getName();
        if(StringUtils.isNotBlank(name)){
            wrapper.eq(ServiceType::getName, name);
        }

        IPage<ServiceType> page = super.page(pageRequest, wrapper);
        return PageVO.convert(page);
    }
}
